/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MRPForm.java
 *
 * Created on 09/11/2013, 08:26:31
 */
package Formularios;

import Classes.ProdutoClass;
import DAO.MRPDAO;
import javax.swing.table.DefaultTableModel;
import java.awt.Color; 
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;



/**
 *
 * @author Carlos Schaefer
 */
public class MRPForm extends javax.swing.JFrame {

    
    
    private int Codigo;
    private int posicaoClique;
    private int NumeroLinhasProduto;
    private int somaMateriaPrima;
    private int codmateria;
    private int aux;
    private int aux2;
    /** Creates new form MRPForm */
    
    
    
    public MRPForm() {
        initComponents();
        getContentPane().setBackground(Color.WHITE);
        setExtendedState(MAXIMIZED_BOTH);
        setLocationRelativeTo(null);
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblMRP = new javax.swing.JTable();
        jToggleButton1 = new javax.swing.JToggleButton();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        cboxano = new javax.swing.JComboBox();
        cbxsemestre = new javax.swing.JComboBox();
        filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        filler2 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        filler3 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767));
        filler4 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 32767));
        filler5 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        filler6 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(32767, 0));
        lblAguarde = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 255));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        tblMRP.setBackground(new java.awt.Color(204, 204, 204));
        tblMRP.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        tblMRP.setFont(new java.awt.Font("Tahoma", 0, 10));
        tblMRP.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Codigo", "Produto", "Itens", "1°", "2°", "3°", "4°", "5°", "6°", "7°", "8°", "9°", "10°", "11°", "12°", "13°", "14°", "15°", "16°", "17°", "18°", "19°", "20°", "21°", "22°", "23°", "24°", "25°", "26°", "Reserva"
            }
        ));
        tblMRP.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        tblMRP.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblMRPMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblMRP);
        tblMRP.getColumnModel().getColumn(0).setMinWidth(0);
        tblMRP.getColumnModel().getColumn(0).setPreferredWidth(0);
        tblMRP.getColumnModel().getColumn(0).setMaxWidth(20);
        tblMRP.getColumnModel().getColumn(1).setMinWidth(100);
        tblMRP.getColumnModel().getColumn(1).setPreferredWidth(100);
        tblMRP.getColumnModel().getColumn(1).setMaxWidth(200);
        tblMRP.getColumnModel().getColumn(2).setMinWidth(100);
        tblMRP.getColumnModel().getColumn(2).setPreferredWidth(100);
        tblMRP.getColumnModel().getColumn(2).setMaxWidth(100);
        tblMRP.getColumnModel().getColumn(29).setMinWidth(0);
        tblMRP.getColumnModel().getColumn(29).setPreferredWidth(0);
        tblMRP.getColumnModel().getColumn(29).setMaxWidth(0);

        jToggleButton1.setText("Executar");
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel2.setText("MRP");

        jLabel1.setText("Ano: ");

        cboxano.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", " " }));
        cboxano.setSelectedIndex(4);
        cboxano.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboxanoItemStateChanged(evt);
            }
        });

        cbxsemestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1° Semestre", "2° Semestre" }));
        cbxsemestre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cbxsemestreMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                cbxsemestreMousePressed(evt);
            }
        });
        cbxsemestre.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbxsemestreItemStateChanged(evt);
            }
        });
        cbxsemestre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxsemestreActionPerformed(evt);
            }
        });

        lblAguarde.setText("Aguarde. Carregando dados...");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel2))
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel1)
                .addGap(4, 4, 4)
                .addComponent(cboxano, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(cbxsemestre, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblAguarde, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(598, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addComponent(jToggleButton1))
            .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 1139, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1132, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(filler3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(filler4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(filler5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(1138, Short.MAX_VALUE)
                .addComponent(filler6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addComponent(jLabel2)
                .addGap(6, 6, 6)
                .addComponent(filler6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel1))
                            .addComponent(cboxano, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cbxsemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lblAguarde, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(11, 11, 11)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 587, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(jToggleButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(184, 184, 184)
                        .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(filler4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(filler3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(14, 14, 14)
                                .addComponent(filler2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(filler5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
  private MRPDAO dao = new MRPDAO();
  
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
      
            
      
//    int posAtual = rsMarca.getRow();  
//    // criar modelo de JTable  
//    DefaultTableModel model = new DefaultTableModel(new String[] {"Código","Descrição"}, 0);//Descricao e Codigo sao nomes da tabela no Banco  
//    // posicionar ResultSet no 1. registro  
//    rsMarca.first();  
//    // preencher modelo  
//    do {  
//      model.addRow(new Object[] {rsMarca.getString("CODMARCA"), rsMarca.getString("DESCRICAO")});  
//    } while (rsMarca.next());  
//    // voltando ResultSet para posição anterior;  
//    rsMarca.absolute(posAtual);  
//    // chamando formulário com JTable  
//    FrmLista lista = new FrmLista("Lista de Marcas", model);//Lista de Marcas é o nome que vai "ficar la em cima" do formulario  
//    lista.setVisible(true);  
    
    
}//GEN-LAST:event_jToggleButton1ActionPerformed

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
   if ( (cbxsemestre.getSelectedIndex())==0  ) {
      lblAguarde.setText("Aguarde. Carregando dados...");
      setar1semestre();
      MontarGrid1semestre();
   } else {
      lblAguarde.setText("Aguarde. Carregando dados...");
      setar2semestre();
      MontarGrid2semestre(); 
   } 
}//GEN-LAST:event_formWindowOpened

private void cbxsemestreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxsemestreActionPerformed

}//GEN-LAST:event_cbxsemestreActionPerformed

private void cbxsemestreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbxsemestreMouseClicked

}//GEN-LAST:event_cbxsemestreMouseClicked

private void cbxsemestreItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxsemestreItemStateChanged
  if ( (cbxsemestre.getSelectedIndex())==0  ) {
      lblAguarde.setText("Aguarde. Carregando dados...");
      setar1semestre();
      MontarGrid1semestre();
  } else {
      lblAguarde.setText("Aguarde. Carregando dados...");
      setar2semestre();
      MontarGrid2semestre();
  } 
}//GEN-LAST:event_cbxsemestreItemStateChanged

private void cbxsemestreMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbxsemestreMousePressed
 
}//GEN-LAST:event_cbxsemestreMousePressed

private void cboxanoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboxanoItemStateChanged
   if ( (cbxsemestre.getSelectedIndex())==0  ) {
      lblAguarde.setText("Aguarde. Carregando dados...");
      setar1semestre();
      MontarGrid1semestre();   
   } else {
      lblAguarde.setText("Aguarde. Carregando dados...");
      setar2semestre();
      MontarGrid2semestre();
   } 
}//GEN-LAST:event_cboxanoItemStateChanged

private void tblMRPMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblMRPMouseClicked
    JTableHeader header = tblMRP.getTableHeader();
    header.addMouseListener(new ColumnHeaderListener());
    
}//GEN-LAST:event_tblMRPMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MRPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MRPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MRPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MRPForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MRPForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cboxano;
    private javax.swing.JComboBox cbxsemestre;
    private javax.swing.Box.Filler filler1;
    private javax.swing.Box.Filler filler2;
    private javax.swing.Box.Filler filler3;
    private javax.swing.Box.Filler filler4;
    private javax.swing.Box.Filler filler5;
    private javax.swing.Box.Filler filler6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JLabel lblAguarde;
    private javax.swing.JTable tblMRP;
    // End of variables declaration//GEN-END:variables

    
            
        
    private void setar2semestre() {
         int indice = 27; 
         for (int i = 3; i < 29; i++){
             tblMRP.getColumnModel().getColumn(i).setHeaderValue(""+indice+"°");   
             indice=indice+1;
         }
         tblMRP.getTableHeader().repaint();
    }

    private void setar1semestre() {
         int indice = 1; 
         for (int i = 3; i < 29; i++){
             tblMRP.getColumnModel().getColumn(i).setHeaderValue(""+indice+"°");   
             indice=indice+1;
         }
         tblMRP.getTableHeader().repaint();
    }

    private void MontarGrid1semestre() {
        lblAguarde.setText("Aguarde. Carregando dados...");
        DefaultTableModel model  = (DefaultTableModel) tblMRP.getModel();
        model.setNumRows(0);        
        //lblAguarde.setText("Aguarde. Carregando dados...");

        
                            for (ProdutoClass Produto : dao.ListarProduto()) {

                                Codigo=Produto.getId();
                                model.addRow(new String[]{
                                            "" + Produto.getId(),
                                            "" + Produto.getDescricao(),
                                            "Necessidade bruta",
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  1),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  2),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  3),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  4),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  5),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  6),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  7),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  8),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  9),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  10),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  11),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  12),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  13),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  14),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  15),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  16),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  17),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  18),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  19),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  20),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  21),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  22),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  23),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  24),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  25),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  26),
                                            "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  27)
                                        });

                                model.addRow(new String[]{"","","Em-Mãos "});//pegar do banco de dados da empresa

                                model.addRow(new String[]{"",
                                                          "",
                                                          "Necessidade Liquida",
                                                          ""+model.getValueAt(model.getRowCount()-2, 3).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 4).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 5).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 6).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 7).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 8).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 9).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 10).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 11).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 12).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 13).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 14).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 15).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 16).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 17).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 18).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 19).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 20).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 21).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 22).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 23).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 24).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 25).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 26).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 27).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 28).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 29).toString()
                                });

                                model.addRow(new String[]{"","","Produção ",
                                                          ""+model.getValueAt(model.getRowCount()-1, 4).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 5).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 6).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 7).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 8).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 9).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 10).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 11).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 12).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 13).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 14).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 15).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 16).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 17).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 18).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 19).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 20).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 21).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 22).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 23).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 24).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 25).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 26).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 27).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 28).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 29).toString()
                                });

                            }
       
        NumeroLinhasProduto =  tblMRP.getRowCount();
        
        model.addRow(new String[]{
                        "_______",
                        "_______________________",
                        "_______________________",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______"
       });
       
       List materias = dao.materiaprimas();
       for (int y=0;y<(materias.size());y++ ){
            Object[] caneta = (Object[]) materias.get(y);
            codmateria=Integer.parseInt(""+caneta[0]);         
            
                   List Listamateria = dao.materiaprimapertence(codmateria);
                       for (int percoreTodasmaterias=0;percoreTodasmaterias<(Listamateria.size());percoreTodasmaterias++ ) {
                            Object[] obj = (Object[]) Listamateria.get(percoreTodasmaterias);

                                            

                                            
                       
      
      
      
                            model.addRow(new String[]{
                                        "" + obj[0],//0
                                        "" + obj[1],//1
                                        "Necessidade bruta",//2
                                        ""+numerodemateriaprimanasemana(1, codmateria),//3
                                        ""+numerodemateriaprimanasemana(2, codmateria),
                                        ""+numerodemateriaprimanasemana(3, codmateria),
                                        ""+numerodemateriaprimanasemana(4, codmateria),
                                        ""+numerodemateriaprimanasemana(5, codmateria),
                                        ""+numerodemateriaprimanasemana(6, codmateria),
                                        ""+numerodemateriaprimanasemana(8, codmateria),
                                        ""+numerodemateriaprimanasemana(9, codmateria),
                                        ""+numerodemateriaprimanasemana(10, codmateria),
                                        ""+numerodemateriaprimanasemana(11, codmateria),
                                        ""+numerodemateriaprimanasemana(12, codmateria),
                                        ""+numerodemateriaprimanasemana(13, codmateria),
                                        ""+numerodemateriaprimanasemana(14, codmateria),
                                        ""+numerodemateriaprimanasemana(15, codmateria),
                                        ""+numerodemateriaprimanasemana(16, codmateria),
                                        ""+numerodemateriaprimanasemana(17, codmateria),
                                        ""+numerodemateriaprimanasemana(18, codmateria),
                                        ""+numerodemateriaprimanasemana(19, codmateria),
                                        ""+numerodemateriaprimanasemana(20, codmateria),
                                        ""+numerodemateriaprimanasemana(21, codmateria),
                                        ""+numerodemateriaprimanasemana(22, codmateria),
                                        ""+numerodemateriaprimanasemana(23, codmateria),
                                        ""+numerodemateriaprimanasemana(24, codmateria),
                                        ""+numerodemateriaprimanasemana(25, codmateria),
                                        ""+numerodemateriaprimanasemana(26, codmateria),
                                        ""+numerodemateriaprimanasemana(27, codmateria),//29


                                    });

                            model.addRow(new String[]{
                                       "",
                                       "",
                                       "Em-Mãos "
                            });

                            model.addRow(new String[]{"",
                                                          "",
                                                          "Necessidade Liquida",
                                                          ""+model.getValueAt(model.getRowCount()-2, 3).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 4).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 5).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 6).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 7).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 8).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 9).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 10).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 11).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 12).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 13).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 14).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 15).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 16).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 17).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 18).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 19).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 20).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 21).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 22).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 23).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 24).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 25).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 26).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 27).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 28).toString()
                            });

                            model.addRow(new String[]{"","","Produção ",
                                
                                                          ""+model.getValueAt(model.getRowCount()-1, 3).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 4).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 5).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 6).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 7).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 8).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 9).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 10).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 11).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 12).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 13).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 14).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 15).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 16).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 17).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 18).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 19).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 20).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 21).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 22).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 23).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 24).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 25).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 26).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 27).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 28).toString()
                                       
                            });


                        }
       
       
       
       
       }
       
      
       
       lblAguarde.setText("");
    }

    private void MontarGrid2semestre() {
        lblAguarde.setText("Aguarde. Carregando dados...");
        DefaultTableModel model  = (DefaultTableModel) tblMRP.getModel();       

        model.setNumRows(0); 
        for (ProdutoClass Produto : dao.ListarProduto()) {
            
            Codigo=Produto.getId();
            model.addRow(new String[]{
                        "" + Produto.getId(),
                        "" + Produto.getDescricao(),
                        "Necessidade bruta",
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  27),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  28),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  29),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  30),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  31),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  32),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  33),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  34),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  35),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  36),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  37),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  38),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  39),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  40),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  41),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  42),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  43),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  44),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  45),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  46),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  47),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  48),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  49),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  50),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  51),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString()), Codigo,  52),
                        "" + dao.ProdutoNaSemana(Integer.parseInt(cboxano.getSelectedItem().toString())+1, Codigo,  1)
                        
                    });
            
            
            
            
            model.addRow(new String[]{"","","Em-Mãos "});//pegar do banco de dados da empresa
            
            model.addRow(new String[]{"",
                                      "",
                                      "Necessidade Liquida",
                                      ""+model.getValueAt(model.getRowCount()-2, 3).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 4).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 5).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 6).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 7).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 8).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 9).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 10).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 11).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 12).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 13).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 14).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 15).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 16).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 17).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 18).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 19).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 20).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 21).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 22).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 23).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 24).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 25).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 26).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 27).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 28).toString(),
                                      ""+model.getValueAt(model.getRowCount()-2, 29).toString()
            
            });
            
            
            model.addRow(new String[]{"","","Produção ",
                                      
                                      ""+model.getValueAt(model.getRowCount()-1, 4).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 5).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 6).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 7).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 8).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 9).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 10).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 11).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 12).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 13).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 14).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 15).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 16).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 17).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 18).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 19).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 20).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 21).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 22).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 23).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 24).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 25).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 26).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 27).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 28).toString(),
                                      ""+model.getValueAt(model.getRowCount()-1, 29).toString()
           
            });
            
        }
        
        NumeroLinhasProduto =  tblMRP.getRowCount();
        
        model.addRow(new String[]{
                        "_______",
                        "_______________________",
                        "_______________________",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______",
                        "_______"
       });
       
       List materias = dao.materiaprimas();
       for (int y=0;y<(materias.size());y++ ){
            Object[] caneta = (Object[]) materias.get(y);
            codmateria=Integer.parseInt(""+caneta[0]);         
            
                   List Listamateria = dao.materiaprimapertence(codmateria);
                       for (int percoreTodasmaterias=0;percoreTodasmaterias<(Listamateria.size());percoreTodasmaterias++ ) {
                            Object[] obj = (Object[]) Listamateria.get(percoreTodasmaterias);

                                            

                                            
                       
      
      
      
                            model.addRow(new String[]{
                                        "" + obj[0],//0
                                        "" + obj[1],//1
                                        "Necessidade bruta",//2
                                        ""+numerodemateriaprimanasemana(1, codmateria),//3
                                        ""+numerodemateriaprimanasemana(2, codmateria),
                                        ""+numerodemateriaprimanasemana(3, codmateria),
                                        ""+numerodemateriaprimanasemana(4, codmateria),
                                        ""+numerodemateriaprimanasemana(5, codmateria),
                                        ""+numerodemateriaprimanasemana(6, codmateria),
                                        ""+numerodemateriaprimanasemana(8, codmateria),
                                        ""+numerodemateriaprimanasemana(9, codmateria),
                                        ""+numerodemateriaprimanasemana(10, codmateria),
                                        ""+numerodemateriaprimanasemana(11, codmateria),
                                        ""+numerodemateriaprimanasemana(12, codmateria),
                                        ""+numerodemateriaprimanasemana(13, codmateria),
                                        ""+numerodemateriaprimanasemana(14, codmateria),
                                        ""+numerodemateriaprimanasemana(15, codmateria),
                                        ""+numerodemateriaprimanasemana(16, codmateria),
                                        ""+numerodemateriaprimanasemana(17, codmateria),
                                        ""+numerodemateriaprimanasemana(18, codmateria),
                                        ""+numerodemateriaprimanasemana(19, codmateria),
                                        ""+numerodemateriaprimanasemana(20, codmateria),
                                        ""+numerodemateriaprimanasemana(21, codmateria),
                                        ""+numerodemateriaprimanasemana(22, codmateria),
                                        ""+numerodemateriaprimanasemana(23, codmateria),
                                        ""+numerodemateriaprimanasemana(24, codmateria),
                                        ""+numerodemateriaprimanasemana(25, codmateria),
                                        ""+numerodemateriaprimanasemana(26, codmateria),
                                        ""+numerodemateriaprimanasemana(27, codmateria),//29


                                    });

                            model.addRow(new String[]{
                                       "",
                                       "",
                                       "Em-Mãos "
                            });

                            model.addRow(new String[]{"",
                                                          "",
                                                          "Necessidade Liquida",
                                                          ""+model.getValueAt(model.getRowCount()-2, 3).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 4).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 5).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 6).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 7).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 8).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 9).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 10).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 11).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 12).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 13).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 14).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 15).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 16).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 17).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 18).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 19).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 20).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 21).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 22).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 23).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 24).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 25).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 26).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 27).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-2, 28).toString()
                            });

                            model.addRow(new String[]{"","","Produção ",
                                
                                                          ""+model.getValueAt(model.getRowCount()-1, 3).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 4).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 5).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 6).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 7).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 8).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 9).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 10).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 11).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 12).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 13).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 14).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 15).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 16).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 17).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 18).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 19).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 20).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 21).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 22).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 23).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 24).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 25).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 26).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 27).toString(),
                                                          ""+model.getValueAt(model.getRowCount()-1, 28).toString()
                                       
                            });


                        }
       
       
       
       
       }
       
      
       
       lblAguarde.setText("");
        
        
        
        
    }

    
    
    
    
    
    
    class ColumnHeaderListener extends MouseAdapter {
       public void mouseClicked(MouseEvent evt) {
         JTable table = ((JTableHeader)evt.getSource()).getTable();
         TableColumnModel colModel = table.getColumnModel();
    
         // índice da coluna cujo titulo foi clicado
         int vColIndex = colModel.getColumnIndexAtX(evt.getX());
         int mColIndex = table.convertColumnIndexToModel(vColIndex);
    
         if(vColIndex == -1) {
             return;
         }
         JOptionPane.showMessageDialog(null, "O clique ocorreu no titulo da coluna com indice " + tblMRP.getColumnModel().getColumn(mColIndex).getHeaderValue()+"\nData inicial e final do periodo!"); 
         
         //System.out.println("O clique ocorreu no titulo da coluna com indice " + mColIndex);
         
       }
        
    }
    
    
        private String Data_Inicial(int semana, int ano) {
        
        //Date dt_inicial= new Date();
        
        Calendar c = Calendar.getInstance();
        c.set(ano,00,01);
        c.add(Calendar.WEEK_OF_YEAR,semana );
        c.add(Calendar.DAY_OF_YEAR,-1 );
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM  );
        
        return (df.format(c.getTime()));
        
    }
    
    
    private String Data_final(int semana, int ano) {
        
        //Date dt_inicial= new Date();
        
        Calendar c = Calendar.getInstance();
        c.set(ano,00,01);
        c.add(Calendar.WEEK_OF_YEAR,semana+1 );
        c.add(Calendar.DAY_OF_YEAR,-1 );
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM  );
        
        return (df.format(c.getTime()));
        
    }
    
     private int numerodemateriaprimanasemana(int semana, int materiaprima){
         somaMateriaPrima=0;
         for (int percoregridpID = 0; percoregridpID < NumeroLinhasProduto-1; percoregridpID++){
                                                  //percor as linhas até encontrar o produto.
             
                                                            List lista = dao.materiaprimapertence(materiaprima);
                                                            for (int percoreArraydemateria = 0; percoreArraydemateria < lista.size(); percoreArraydemateria++){
                                                                Object[] testatud = (Object[]) lista.get(percoreArraydemateria);
                                                                
                                                                 try{
                                                                    aux = Integer.parseInt(tblMRP.getValueAt(percoregridpID, 0).toString());
                                                                    aux2= Integer.parseInt(""+testatud[2]);
                                                                }catch(Throwable e){
                                                                    aux=0;
                                                                }
                                                                
                                                                if (aux    ==   aux2){
                                                                    try{
                                                                        somaMateriaPrima=somaMateriaPrima+Integer.parseInt(tblMRP.getValueAt(percoregridpID+3, semana+2).toString());
                                                                    }catch(Throwable e){
                                                                        
                                                                    }
                                                                }
                                                            }

                                                      //se tiver somar a quantidade da necessidade
                                            }
    
           return somaMateriaPrima;
     }
    
    
    
}
